/* 

Replication syntax CPS article
"Social change and women's left vote. The role of employment, education, and marriage in the gender vote gap"

Dr. Mathilde M. van Ditmars, University of Lucerne & University of Zurich
Dr. Rosalind Shorrocks, University of Manchester
May 2024 (Stata version 18)

File 1/4. G-SOEP Data preparation and analyses for Tables
*/

*German Socio-Economic Panel (SOEP), 1984-2018
*Data version used: G-SOEP data v35; DOI: 10.5684/soep.v35.
*see https://www.diw.de/sixcms/detail.php?id=diw_01.c.742256.en


*DATASET WORKING FILE CREATION*

clear all
set more off, permanently
capture log close

global data "DEFINE"
global temp "DEFINE"
global output "DEFINE"
cd  "DEFINE"

use pid syear e11105 using ${data}pequiv, clear // key variable is e11105 (isco-88 at 4-digit level)
rename e11105 isco_mainjob // Current occupation of respondent, coded with isco88 4-digit

*merge with needed variables from personal long file
merge 1:1 pid syear using ${data}pl, ///
	keepusing(hid plh0004 plh0011_h plh0012_h plh0013_h plb0022_h ///
	plb0057_h-plb0065 plb0067 plb0068 plc0013_h plc0014_h pli0098_v2) ///
 keep(match) nogen // only people who answered the survey

*merge with pgen variables
sort pid syear
merge 1:1 pid syear using ${data}pgen, keepusing (pgnation pgisei08 pgisei88 pgsiops08 pgsiops88 pgisced97 pgisced11 ///
pgisco08 pgisco88 pgfamstd pgegp88 pgegp08) keep (match) nogen

*merge with ppfad variables 
sort pid syear
merge 1:1 pid syear using ${data}ppathl, keepusing (loc1989 sex gebjahr) keep (match) nogen
sort pid syear
save ${temp}longfile_temp, replace

*merge with household variables
sort hid syear
merge m:1 hid syear using ${data}hl, keepusing (hlc0005_h hlc0043) keep (match) nogen
sort pid syear

label language EN

*select variables to keep
keep pid syear isco_mainjob hid plb0022_h plh0004 plh0011_h plh0012_h plh0013_h pli0098_v2 pgnation pgfamstd pgisced97 sex gebjahr loc1989 hlc0043 hhnr 


* Set the variables that order the panel
sort pid syear
xtset pid syear
save $datadest/GSOEP_workfile, replace


*RECODING*

recode _all (-1=.a)(-2=.b)(-3=.c)(-4=.d)(-5=.e)(-6=.f)(-7=.g)(-8=.h) 
/* 
-1 	no answer / don't know
-2 	does not apply
-3 	implausible value
-4 	Inadmissible multiple response
-5 	Not included in this version of the questionnaire
-6 	Version of questionnaire with modified filtering
-8 	Question not part of the survey program this year
*/ 

*gen age variable
gen age=(syear-gebjahr)
tab age

*gender
gen female=0
replace female=1 if sex==2
tab female

*recode civil status // widowers are excluded
tab pgfamstd 
recode pgfamstd (3=0 "single") (1 6 7 8 =1 "married/partnership") (2 4=2 "divorced/separated") (5=.), ///
gen (civsta_3)
tab civsta_3

*labour force participation
tab plb0022_h
recode plb0022_h (1 2=1 "employed") (.a .c .e=.) (else=0 "not employed"), gen(work)
tab work

*part-time and full-time work vs. everything else
tab plb0022_h
recode plb0022_h (1 = 1 "fulltime employed") (.a .c .e =.) (else=0 "parttime/not employed"), gen(ftwork)

recode plb0022_h (2 = 1 "parttime employed") (.a .c .e =.) (else=0 "fulltime/not employed"), gen(ptwork)

*3 categories: part-time, full-time, not working, vs. everything else
recode plb0022_h (1 = 1 "FT employed") (2 = 2 "PT employed") (9 = 3 "not employed") (.a .c .e=.) (else=0 "other"), gen(work3)

tab1 work work3 ftwork ptwork

*level of education
tab pgisced97
recode pgisced97 (0=0 "still in school") (1/2=1 "low") (3/4=2 "medium") (5/6=3 "high"), gen(educat_3)
tab1 pgisced97 educat_3

*educational categories
capture drop edu4
recode pgisced97 (0/2=1)(3/4=2)(5=3)(6=4), gen(edu4)
label define edu4 ///
1 "Less than upper secondary education" /// primary education [isced 1&2]
2 "Upper secondary education" /// apprenticeship, vocational school, Abitur [isced 3&4]
3 "Post-secondary/tertiary vocational" /// vocational post-secondary (Hochschule)
4 "University" // University
label values edu4 edu4
tab edu4

*religiosity
tab pli0098_v2
recode pli0098_v2 (1/3=1 "once a month or up") (4/5=0 "few times a year or less"), gen(reli)

//replace from previous waves if missing
gen reli_c=reli
bysort pid (syear) : replace reli_c=reli_c[_n-1] if missing(reli_c)

tab reli_c syear

*party leaning/identification
label define PID 1 "yes" 2 "no" 3 "no answer"
label values plh0011_h PID
tab plh0011_h
tab plh0012_h

*SPD identification/preference
recode plh0012_h (1=1 "SPD") (2/31=0 "other PID"), gen(SPD)
replace SPD=. if plh0011_h==2 | plh0011_h==3
tab SPD

*Left party identification/preference excl. Greens
recode plh0012_h (1=1 "SPD/Die Linke") (2/5=0 "other PID") (6=1 "SPD/Die Linke") (7/31=0 "other PID"), gen(left)
replace left=. if plh0011_h==2 | plh0011_h==3
tab left

*Left party identification/preference incl. Greens
recode plh0012_h (1=1 "SPD/Die Linke/Greens") (2/4=0 "other PID") (5=1 "SPD/Die Linke/Greens") /// 
(6=1 "SPD/Die Linke/Greens") (7/31=0 "other PID"), gen(left_green)
replace left_green=. if plh0011_h==2 | plh0011_h==3
tab left_green

*nationality
tab pgnation
recode pgnation (1=1 "German") (else=0 "other"), gen(german)
tab german

*kids // people with more than 9 kids are excluded
tab hlc0043
recode hlc0043 (.b=0 "no kids") (1/9=1 "kids") (else=.), gen(kids)
tab kids


* Generations of respondents
recode gebjahr (1882/1964=3) (1965/1980=4) (1981/2005=5), gen(cohort)
// "Baby boomers 1946-1964" ///
// "Gen X 1965-1980" ///
//"Millennials 1981-1996"
 
label define cohort ///
3 "Baby boomers and older" ///
4 "Gen X" ///
5 "Millennials and younger"
label values cohort cohort
tab cohort



/*transitions:

1. EDUCATION
*a. obtaining a post-secondary vocational degree
*b. obtaining a university degree

2. EMPLOYMENT
* a. employed —> economic inactivity/housework
* b. full-time work -> part-time work
* c. part-time work —> full-time work
* d. economic inactivity/housework -> employed
* e. education -> employed 

4. CIVIL STATUS
*a. unmarried -> married/reg. partnership
*b. married/reg. partnership -> divorced/separated

==> these transitions will overlap for some people, e.g. students working part-time

*/



*Count number of waves per person

* Generate an identifier for the first time an individual was included in the sample and one for the last time
sort pid syear
bysort pid: gen total= _N
bysort pid: gen num_wave= _n
gen last_obs= total==num_wave

by pid, sort: gen nfirst= _n==1
count if nfirst
by pid, sort: gen nlast= _n==_N
count if nlast

tab nfirst nlast

tab nfirst if nfirst==1 & nlast==1


*1. EDUCATIONAL transitions

*obtaining upper secondary degree
capture drop first_edu2 //[first observation of this level of education]
bysort pid (syear): gen first_edu2 = (edu4[_n-1]<2 & edu4==2)

*identify wave number in which obtained the degree:
capture drop edu2_fw // [first wave after transition]
by pid (syear): gen edu2_fw=num_wave if first_edu2==1

*impute this wave number for all person-years
capture drop wave_edu2
by pid (syear): egen wave_edu2=max(edu2_fw) 

*define transition variable for wave of transition + those after
capture drop edu2_trans
gen edu2_trans=0

*keep 1 after the transition
bysort pid (syear): replace edu2_trans=1 if edu4==2 & num_wave>=wave_edu2

label var edu2_trans "got upper sec degree"
xttab edu2_trans

*a. obtaining a post-secondary vocational degree
capture drop first_edu3 //[first observation of this level of education]
bysort pid (syear): gen first_edu3 = (edu4[_n-1]<3 & edu4==3)

*identify wave number in which obtained the degree:
capture drop edu3_fw // [first wave after transition]
by pid (syear): gen edu3_fw=num_wave if first_edu3==1

*impute this wave number for all person-years
capture drop wave_edu3
by pid (syear): egen wave_edu3=max(edu3_fw) 

*define transition variable for wave of transition + those after
capture drop edu3_trans
gen edu3_trans=0

bysort pid (syear): replace edu3_trans=1 if edu4==3 & num_wave>=wave_edu3

label var edu3_trans "got vocat post-sec degree"
xttab edu3_trans 

*b. obtaining a university degree
capture drop first_edu4 //[first observation of this level of education]
bysort pid (syear): gen first_edu4 = (edu4[_n-1]<4 & edu4==4)

*identify wave number in which obtained the degree:
capture drop edu4_fw // [first wave after transition]
by pid (syear): gen edu4_fw=num_wave if first_edu4==1

*impute this wave number for all person-years
capture drop wave_edu4
by pid (syear): egen wave_edu4=max(edu4_fw) 

*define transition variable for wave of transition + those after
capture drop edu4_trans
gen edu4_trans=0

bysort pid (syear): replace edu4_trans=1 if edu4==4 & num_wave>=wave_edu4

label var edu4_trans "got uni degree"
xttab edu4_trans 

*2. LABOUR MARKET/WORK transitions
* a. work —> economic inactivity/housework
* b. full-time work -> part-time work
* c. part-time work —> full-time work
* d. economic inactivity/housework (unemployed + man/woman at home) -> work
* e. education -> work


*a. work —> economic inactivity/housework (unemployed + man/woman at home)

capture drop first_wrk1 //[first observation after making this work/employment transition]
bysort pid (syear): gen first_wrk1 = (work[_n-1]==1 & work3==3) // first work, then econ inactive

*identify wave number in which made the transition:
capture drop wrk1_fw // [first wave after transition]
by pid (syear): gen wrk1_fw=num_wave if first_wrk1==1

*impute this wave number for all person-years
capture drop wave_wrk1
by pid (syear): egen wave_wrk1=max(wrk1_fw) 

*define transition variable for wave of transition + those after
capture drop wrk1_trans
gen wrk1_trans=0

bysort pid (syear): replace wrk1_trans=1 if work3==3 & num_wave>=wave_wrk1

label var wrk1_trans "work to econ inactive"
xttab wrk1_trans 

*b. full-time work -> part-time work

capture drop first_wrk2 //[first observation after making this work/employment transition]
bysort pid (syear): gen first_wrk2 = (work3[_n-1]==1 & work3==2) // first FT work, then PT work

*identify wave number in which made the transition:
capture drop wrk2_fw // [first wave after transition]
by pid (syear): gen wrk2_fw=num_wave if first_wrk2==1

*impute this wave number for all person-years
capture drop wave_wrk2
by pid (syear): egen wave_wrk2=max(wrk2_fw) 

*define transition variable for wave of transition + those after
capture drop wrk2_trans
gen wrk2_trans=0

bysort pid (syear): replace wrk2_trans=1 if work3==2 & num_wave>=wave_wrk2

label var wrk2_trans "FT to PT work"
xttab wrk2_trans


*c. part-time work —> full-time work

capture drop first_wrk3 //[first observation after making this work/employment transition]
bysort pid (syear): gen first_wrk3 = (work3[_n-1]==2 & work3==1) // first PT work, then FT work

*identify wave number in which made the transition:
capture drop wrk3_fw // [first wave after transition]
by pid (syear): gen wrk3_fw=num_wave if first_wrk3==1

*impute this wave number for all person-years
capture drop wave_wrk3
by pid (syear): egen wave_wrk3=max(wrk3_fw) 

*define transition variable for wave of transition + those after
capture drop wrk3_trans
gen wrk3_trans=0

bysort pid (syear): replace wrk3_trans=1 if work3==1 & num_wave>=wave_wrk3

label var wrk3_trans "PT to FT work"
xttab wrk3_trans


*d. economic inactivity/housework (unemployed + man/woman at home) -> work
capture drop first_wrk4 //[first observation after making this work/employment transition]
bysort pid (syear): gen first_wrk4 = (work3[_n-1]==3 & pgisced97[_n-1]!=0 & work==1) // first econ inactive (NOT in education), then work

*identify wave number in which made the transition:
capture drop wrk4_fw // [first wave after transition]
by pid (syear): gen wrk4_fw=num_wave if first_wrk4==1

*impute this wave number for all person-years
capture drop wave_wrk4
by pid (syear): egen wave_wrk4=max(wrk4_fw) 

*define transition variable for wave of transition + those after
capture drop wrk4_trans
gen wrk4_trans=0

bysort pid (syear): replace wrk4_trans=1 if work==1 & num_wave>=wave_wrk4

label var wrk4_trans "econ inactive to work"
xttab wrk4_trans 

*e. education -> employed
capture drop first_lb //[first observation in the labour market after being in education]
bysort pid (syear): gen first_lb = ((pgisced97[_n-1]==0 | plb0022_h[_n-1]==3) & work==1)

*identify wave number in which obtained the degree:
capture drop lb_fw // [first wave after transition]
by pid (syear): gen lb_fw=num_wave if first_lb==1

*impute this wave number for all person-years
capture drop wave_lb
by pid (syear): egen wave_lb=max(lb_fw) 

*define transition variable for wave of transition + those after
capture drop lb_trans
gen wrk5_trans=0

bysort pid (syear): replace wrk5_trans=1 if work==1 & num_wave>=wave_lb

label var wrk5_trans "edu to work"
xttab wrk5_trans 

//additional code for post/sec tertiary vocational and university [only in DE code]

*c. post/sec tertiary vocational -> employed
capture drop first_lb3 //[first observation in the labour market after being in education]
bysort pid (syear): gen first_lb3 = ((work==1 & edu4==3) & num_wave>=wave_edu3) 

*identify wave number in which made the transition:
capture drop lb3_fw // [first wave after transition]
by pid (syear): gen lb3_fw=num_wave if first_lb3==1

*impute this wave number for all person-years
capture drop wave_lb3
by pid (syear): egen wave_lb3=max(lb3_fw) 

*define transition variable for wave of transition + those after
capture drop lb3_trans
gen lb3_trans=0

bysort pid (syear): replace lb3_trans=1 if work==1 & edu4==3 & num_wave>=wave_lb3

label var lb3_trans "tert voc to work"
xttab lb3_trans // 993 people (1.1%)

*add this information to the previously defined wrk5_trans variable
bysort pid (syear): replace wrk5_trans=1 if lb3_trans==1 & num_wave>=wave_lb3

xttab wrk5_trans 

*d. university -> employed 
capture drop first_lb4 //[first observation in the labour market after being in education]
bysort pid (syear): gen first_lb4 = ((work==1 & edu4==4) & num_wave>=wave_edu4) 

*identify wave number in which made the transition:
capture drop lb4_fw // [first wave after transition]
by pid (syear): gen lb4_fw=num_wave if first_lb4==1

*impute this wave number for all person-years
capture drop wave_lb4
by pid (syear): egen wave_lb4=max(lb4_fw) 

*define transition variable for wave of transition + those after
capture drop lb4_trans
gen lb4_trans=0

bysort pid (syear): replace lb4_trans=1 if work==1 & edu4==4 & num_wave>=wave_lb4

label var lb4_trans "uni to work"
xttab lb4_trans // 1922 people (2.1%)

*add this information to the previously defines wrk5_trans variable
bysort pid (syear): replace wrk5_trans=1 if lb4_trans==1 & num_wave>=wave_lb4

xttab wrk5_trans 


*3. CIVIL STATUS

*a. unmarried to married
capture drop first_civ1 //[first observation after making this transition]
bysort pid (syear): gen first_civ1 = (civsta_3[_n-1]==0 & civsta_3==1) // first unmarried, then married/reg part

*identify wave number in which made the transition:
capture drop civ1_fw // [first wave after transition]
by pid (syear): gen civ1_fw=num_wave if first_civ1==1

*impute this wave number for all person-years
capture drop wave_civ1
by pid (syear): egen wave_civ1=max(civ1_fw) 

*define transition variable for wave of transition + those after
capture drop civ1_trans
gen civ1_trans=0

bysort pid (syear): replace civ1_trans=1 if civsta_3==1 & num_wave>=wave_civ1

label var civ1_trans "unmarried to married/reg partnership"
xttab civ1_trans 



*b. married to divorced/separated
capture drop first_civ2 //[first observation after making this transition]
bysort pid (syear): gen first_civ2 = (civsta_3[_n-1]==1 & civsta_3==2) // first married, then divorced/separated

*identify wave number in which made the transition:
capture drop civ2_fw // [first wave after transition]
by pid (syear): gen civ2_fw=num_wave if first_civ2==1

*impute this wave number for all person-years
capture drop wave_civ2
by pid (syear): egen wave_civ2=max(civ2_fw) 

*define transition variable for wave of transition + those after
capture drop civ2_trans
gen civ2_trans=0

bysort pid (syear): replace civ2_trans=1 if civsta_3==2 & num_wave>=wave_civ2

label var civ2_trans "married/partnership to divorced/separated"
xttab civ2_trans 


*ANALYSIS*

set scheme cleanplots
numlabel, add

*analytic sample

* Define analytic sample: all respondents under age 67 but older than 17 (voting age)
capture drop sample
gen sample=0
replace sample=1 if age>17 & age<67 & german==1

keep if sample==1
//consider just putting this in the analysis line (if sample==1) so that we can change the sample composition

*Reduce observations to 1999 and later, for comparison with CH
keep if syear>1998

*MODELS*

*1. baseline model (Table S1)

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
outreg2 using "${output}/GSOEP_baseline.xls", replace ctitle(left_gr FE) label

*add BE effects for comparison
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, be
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(left_gr BE) label

*replicate without the Greens (Table S3)
xtreg left i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(left FE) label

*add BE effects for comparison
xtreg left i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, be
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(left BE) label


//robustness check: without adding year dummies, but including age (Table S5)
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids age, fe vce(cluster pid)
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(left_gr FE 2) label

*add BE effects for comparison
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids age, be
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(left_gr BE 2) label

//robustness check: including year dummies, and including cohort. only for BE possible (Table S5)
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.cohort i.syear, be
outreg2 using "${output}/GSOEP_baseline.xls", append ctitle(cohort BE) label


*2. TRANSITION ANALYSIS 

// using analytic sample of baseline models
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
capture drop sample_trans
gen sample_trans=1 if e(sample)

//Table S2
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==1 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", replace ctitle(left_gr women) label

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==0 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", append ctitle(left_gr men) label


// replicate without year dummies but controlling for age: (Table S6)
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids age, fe vce(cluster pid), if female==1 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", append ctitle(left_gr women 2) label

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids age, fe vce(cluster pid), if female==0 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", append ctitle(left_gr men 2) label


*replicate without the Greens (Table S4)
xtreg left civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids i.syear, fe vce(cluster pid), if female==1 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", append ctitle(left women) label
// results relatively similar to previous model, main difference now instead of edu3_trans, wrk3 is sign (positive)

xtreg left civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==0 & sample_trans==1
outreg2 using "${output}/GSOEP_transitions.xls", append ctitle(left men) label
//no sign. effects


//Table 1
*compute frequencies of transitions in our analytic sample [how many people we observe undergo this]
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids i.syear, fe vce(cluster pid), if sample_trans==1

xttab first_civ1  if e(sample)
xttab first_civ2  if e(sample)
xttab first_edu2  if e(sample)
xttab first_edu3  if e(sample)
xttab first_edu4  if e(sample)
xttab first_wrk1  if e(sample)
xttab first_wrk2  if e(sample)
xttab first_wrk3  if e(sample)
xttab first_wrk4  if e(sample)
xttab first_lb if e(sample)
xttab first_lb3 if e(sample)
xttab first_lb4 if e(sample) // add up these last 3 to get the wrk5_trans people in our analytic sample


***REPLICATE RESULTS WITHOUT RW POPULIST PARTIES IN THE REFERENCE CATEGORY***
recode plh0012_h (1 5 6 =1 "SPD/Die Linke/Greens")(2/4=0 "other PID")(27=.)(7/26 =0 "other PID") (30 31 =0 "other PID"), gen(left_exprp)
replace left_exprp =. if plh0011_h==2 | plh0011_h==3
tab1 left_exprp left_gr,m
//AfD set to missing instead of 0

tab1 plh0012_h left_exprp, m

*1. BASELINE MODELS (Table S7)
xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
outreg2 using "${output}/GSOEP_appendix_PRP_1.xls", replace ctitle(PRP FE) label

*add BE effects for comparison
xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, be
outreg2 using "${output}/GSOEP_appendix_PRP_1.xls", append ctitle(PRP BE) label


*2. TRANSITION ANALYSIS (Table S8)
xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
capture drop sample_trans
gen sample_trans=1 if e(sample)


xtreg left_exprp civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==1 & sample_trans==1
outreg2 using "${output}/GSOEP_appendix_PRP_2.xls", replace ctitle(PRP women) label



xtreg left_exprp civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==0 & sample_trans==1
outreg2 using "${output}/GSOEP_appendix_PRP_2.xls", append ctitle(PRP men) label





*DESCRIPTIVES*
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, be
ttest left_gr, by(female), if e(sample)
// gender gap of .067

ttest left, by(female), if e(sample)


xtreg left_gr female##syear, re, if e(sample)
margins, dydx(female) at(syear=(1999(1)2018)) post coeflegend
est store gendergap

coefplot (gendergap, label(Difference between men and women))||, ///
vertical recast(scatter) ///
rename(1._at=1999 2._at=2000 3._at=2001 4._at=2002 5._at=2003 6._at=2004 7._at=2005 8._at=2006 9._at=2007 ///
10._at=2008 11._at=2009 12._at=2010 13._at=2011 14._at=2012 15._at=2013 16._at=2014 17._at=2015 18._at=2016 ///
19._at=2017 20._at=2018) ///
xlabel(, angle(45)) xscale(lstyle(none)) ytitle("Probability of supporting LW party") yscale(lstyle(none)) ///
yscale (range (-.02 .1)) ylabel(-.02 (.02) .1) yline(0) ///
byopts(legend(position(6))) plotregion(lcolor(gs10) lwidth(small)) yline(0) ///
title("Germany: gender gap in voting", margin(medium)) legend(cols(2) position(6))
graph save "${output}/DE_gendergap_marginsdydx.gph", replace
graph export "${output}/DE_gendergap_marginsdydx.jpg", replace
graph export "${output}/DE_gendergap_marginsdydx.pdf", replace








